package work.MrSun.xyq.controller;

/**
 * @Author MrSun
 * @Date 2023/4/17 10:36
 */

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;
import work.MrSun.xyq.model.XyqShop;
import work.MrSun.xyq.model.XyqShopBusiness;
import work.MrSun.xyq.model.XyqShopImages;
import work.MrSun.xyq.service.XyqShopBusinessService;
import work.MrSun.xyq.service.XyqShopImagesService;
import work.MrSun.xyq.service.XyqShopService;

import java.util.List;

/**
 * 商家信息的控制层
 */
@RestController
public class ShopMessageController {
    @Autowired
    private XyqShopService xyqShopService;

    @Autowired
    private XyqShopImagesService xyqShopImagesService;

    @Autowired
    private XyqShopBusinessService xyqShopBusinessService;
    /**
     * 获取到所有的商家信息
     * @return
     */
    @PostMapping("/getMessage/getAllShop")
    public List<XyqShop>  getAllShopMessage(){
        return xyqShopService.findAll();
    }

    /**
     * 根据id获取到商家的信息----得到指定商店的所有信息。
     * @param id
     * @return
     */
    @PostMapping("/getMessage/getShopMessage/{id}")
    public XyqShop getShopMessageById(@PathVariable Integer id) {
        //根据id获取到商家信息
        XyqShop xyqShop = xyqShopService.getById(id);
        //创建商家图片对象
        XyqShopImages xyqShopImages = new XyqShopImages();
        xyqShopImages.setShopId(id);
        //从数据库中得到商家所有的图片信息
        xyqShop.setShopImages(xyqShopImagesService.findList(xyqShopImages));
        //创建商家营业信息
        XyqShopBusiness mangoShopBusiness = new XyqShopBusiness();
        mangoShopBusiness.setShopId(id);
        xyqShop.setShopBusinesses(xyqShopBusinessService.findList(mangoShopBusiness));
        return xyqShop;
    }
}
